using Microsoft.AspNetCore.Mvc;
using WebapiTemplate.Domain.Entity;
using WebapiTemplate.Application.Common.Interface;

namespace WebapiTemplate.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class FileController : ControllerBase
    {
        //定义操作文件的服务字段
        private readonly IFileService _fileService;






        //依赖注入得到字段的真正服务实例
        public FileController(IFileService fileService)
        {
            _fileService = fileService;
        }




        //根据前端传来的Id返回文件字节流给前端下载
        [HttpGet]
        [Route("dolowdfile")]
        public async Task<dynamic> DolowdFile(Guid Id)
        {
            // //消除跨域问题
            HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");//No 'Access-Control-Allow-Origin' header is present on the requested resource

            return await _fileService.DolowdFile(Id);

        }





        //接收并下载前端文件
        [HttpPost]
        [Route("Upload/FormImg")]
        public async Task<dynamic> Getimages(IFormCollection files)
        {
            // //消除跨域问题
             HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");

             return await _fileService.FileUpload(files);
        }
    }
}
